package com.cos.hospital.ui.patient.adapter;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cos.hospital.R;
import com.cos.hospital.model.bean.HistoryRecordsItemsBean;
import com.cos.hospital.tool.UDate;

import java.util.List;

/**
 * 历史病历适配器
 */
public class HistoryRecordsAdapter extends BaseQuickAdapter<HistoryRecordsItemsBean, BaseViewHolder> {
    private List<HistoryRecordsItemsBean> data;

    public HistoryRecordsAdapter(@Nullable List<HistoryRecordsItemsBean> data) {
        super(R.layout.item_history_records, data);
        this.data = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, HistoryRecordsItemsBean item) {
        int layoutPosition = helper.getLayoutPosition();
        View line_start = helper.getView(R.id.line_start);
        View line_end = helper.getView(R.id.line_end);
        if (layoutPosition == 0 && layoutPosition == (data.size() - 1)) {
            line_start.setVisibility(View.INVISIBLE);
            line_end.setVisibility(View.INVISIBLE);
        } else if (layoutPosition == 0) {
            line_start.setVisibility(View.INVISIBLE);
            line_end.setVisibility(View.VISIBLE);
        } else if (layoutPosition == data.size() - 1) {
            line_start.setVisibility(View.VISIBLE);
            line_end.setVisibility(View.INVISIBLE);
        } else {
            line_start.setVisibility(View.VISIBLE);
            line_end.setVisibility(View.VISIBLE);
        }
        helper.setText(R.id.tv_time, UDate.strToStrSafety(item.getFldSignTime(), "yyyy-MM-dd"));
        helper.setText(R.id.tv_diagnose, item.getFldDiagnose());
        helper.setText(R.id.tv_doctor, "医师：" + item.getFldDoctorName());
    }

}